package com.wk.code.wkserver.controller.admin;


import com.wk.code.wkserver.request.admin.SysUserRequest;
import com.wk.code.wkserver.response.admin.SysUserResponse;
import com.wk.code.wkserver.response.result.R;
import com.wk.code.wkserver.service.ISysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * 管理员控制层
 *
 * @author wq
 * @date 2021-07-12 14:41:53
 */
@RestController
@AllArgsConstructor
@RequestMapping("admin/sysUser")
@Api(tags = "admin-后台系统管理员管理")
public class AdminSysUserController {

    final ISysUserService sysUserService;

    /**
     * 用户登录
     *
     * @param request 请求参数
     * @return R
     */
    @ApiOperation(value = "用户登录", notes = "用户登录")
    @PostMapping("/login")
    public R<SysUserResponse> login(@RequestBody SysUserRequest request) {
        return R.success(sysUserService.login(request));
    }

    /**
     * 用户注册
     *
     * @param request 请求参数
     * @return R
     */
    @ApiOperation(value = "用户注册", notes = "用户注册")
    @PostMapping("/register")
    public R<Void> register(@RequestBody SysUserRequest request) {
        sysUserService.register(request);
        return R.success();
    }

    /**
     * 添加管理员
     *
     * @param req 请求参数
     * @return R
     */
    @ApiOperation(value = "添加管理员", notes = "添加管理员")
    @PostMapping("add")
    public R<Void> add(@RequestBody SysUserRequest req) {
        sysUserService.addUser(req);
        return R.success();
    }



    /**
     * 系统用户分页
     *
     * @param request 请求参数
     * @return R
     */
    @ApiOperation(value = "系统用户分页", notes = "系统用户分页")
    @PostMapping("/page")
    private R<?> page(@RequestBody SysUserRequest request) {
        return R.success(sysUserService.page(request));
    }

    /**
     * 退出登录
     *
     * @return R
     */
    @ApiOperation(value = "退出登录", notes = "退出登录")
    @GetMapping("/logout")
    public R<Void> logout() {
        sysUserService.logout();
        return R.success();
    }

}
